window.zc_store = {
    set: function (key, value) {
        if (typeof value === 'string') {
            sessionStorage.setItem(key, value);
        } else {
            sessionStorage.setItem(key, JSON.stringify(value));
        }
    },
    get: function (key, json_obj) {
        if (json_obj) {
            return JSON.parse(sessionStorage.getItem(key));
        } else {
            return sessionStorage.getItem(key);
        }
    },
    remove: function (key) {
        sessionStorage.removeItem(key);
    }
};
window.zc_store_local = {
    set:function(key,value) {
        if(typeof value ==='string') {
            localStorage.setItem(key, value);
        }else {
            localStorage.setItem(key, JSON.stringify(value));
        }
    },
    get:function(key,json_obj) {
        if(json_obj) {
            return JSON.parse( localStorage.getItem(key) );
        } else {
            return localStorage.getItem(key);
        }
    },
    remove:function(key) {
        localStorage.removeItem(key);
    }
};
function goToComeFrom(argu_name) {
    var curr_url = window.location.href;
    // console.log(curr_url);
    var index = curr_url.indexOf(argu_name);
    // console.log(index);
    var comeArgus = curr_url.substr(index);
    // console.log(comeArgus);
    var toPageUrlBefore = comeArgus.substr(9);
    // console.log(toPageUrlBefore);
    var toPageUrl = toPageUrlBefore.replace('&', '?');
    // console.log(toPageUrl);
    return toPageUrl;
}

function serveUrl() { //域名
    return 'http://106.14.19.71:9090';//预发布
    // return 'http://106.14.239.40:9090';//测试芝麻信用
    //return 'http://javatest.tgljweb.com:9090';//测试
    // return 'http://javaapi.tgljweb.com:9090';//正式
    // return 'http://192.168.65.141:9090';//董传祥本地


}


/*function WFServeUrl() {
    return 'http://192.168.65.183:9090';//王峰本地
}*/

function imagesUrl() { //图片路径
    return 'http://img.tgljweb.com/';
}

function zcGetLocationParm(argu_name, curr_str) { //获取url参数argu_name的值,如果未获取到则返回空,原生JS完成,不依赖$,获取不到时返回空串''
    var i = 0;
    var url = curr_str || window.location.href;
    var arguStr = url.split('?')[1];
    var key_val_s = [];
    var len = 0;
    var result = '';
    if (arguStr) {
        key_val_s = arguStr.split('&');
        len = key_val_s.length;
        for (i = 0; i < len; i++) {
            if (argu_name == key_val_s[i].split('=')[0]) {
                result = key_val_s[i].split('=')[1];
                break;
            }
        }
    }
    return result ? result == 'null' ? '' : result : '';
}

function zcGetAndSetUid() { //获取uid，如果url获取到了就存在本地，否则从本地获取（此处不处理是否获取到@zc），依赖zcGetLocationParm
    var uid = zcGetLocationParm('uid');
    if (uid) {
        zc_store.set('uid', uid);
    }
    if (!uid) {
        uid = zc_store.get('uid', 'json_obj'); //必须转成json格式，否则多一对双引号而报错@zc170612
    }
    return uid;
}

function zcGetAndSetcityCode() { //方法合并优化TODO0623
    var city_code = zcGetLocationParm('city_code') || zcGetLocationParm('currCityCode');
    if (city_code) {
        zc_store.set('init_city_code', city_code);
    }
    if (!city_code) {
        city_code = zc_store.get('init_city_code', 'json_obj'); //必须转成json格式，否则多一对双引号而报错@zc170612
    }
    return city_code;
}

function solveIosHead(headNextHasMt, fn) { //
    var u = navigator.userAgent;
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    var $h_top = $('.h_top');
    var h_top_height = $h_top.height();
    var $h_top_next = $h_top.next();
    var nextMt = h_top_height + 20 + 'px';
    if (isIOS) {
        $h_top.css('padding-top', '20px');
        if (!headNextHasMt) {
            $h_top_next.css('margin-top', nextMt);
        }
        if (fn) {
            fn();
        }
    }

}

function setTargetTop(target, obj) { //设置弹出框的top值以适应ios终端头部下移问题 传递要设置的目标元素和相关联的元素jq对象或者选择器
    var $target = (typeof target === 'string' ? $(target) : target);
    var $obj = (typeof obj === 'string' ? $(obj) : obj);
    var $objOffsetTop = $obj.position().top;
    var $objHeight = $obj.height();
    var $targetTop = Number($objOffsetTop) + Number($objHeight) + 'px';
    $target.css('top', $targetTop);
}


function getLocalTimeByMs(timestamp, argu) {     //将时间戳（毫秒）转换成日期@zc170609
    var zc_new_date_obj = new Date(parseInt(timestamp));
    var zc_year = zc_new_date_obj.getFullYear();
    var zc_month = ( zc_new_date_obj.getMonth() ) + 1;
    var zc_day = zc_new_date_obj.getDate();
    var resultStr = zc_year + '-' + zcAddZero(zc_month) + '-' + zcAddZero(zc_day);
    if (argu) {
        resultStr = zc_year + argu + zcAddZero(zc_month) + argu + zcAddZero(zc_day);
    }
    if (!zc_year || !zc_month || !zc_day) {
        resultStr = '暂无可选日期';
        return resultStr;
    }
    return resultStr;
}


function zcAddZero(num) {
    return num < 10 ? '0' + num : num;
}

function renderAhref($ul, city_code) { //根据传入的ul对象和当前citycode把a链接加上code参数
    var $as = $ul.find('li a');
    $.each($as, function (i, v) {
        // console.log(v.href);
        v.href += '?city_code=' + city_code + '';
    })
}

function rmPageFrom() {
    zc_store.remove('from_app');
    zc_store.remove('come_from');
}

function startTimeToDate(obj){ // 日历开始时间
    var datatime = new Date(obj);
    var year = datatime.getFullYear();
    var month = datatime.getMonth()+1;
    if(month<10){month="0"+month};
    var day = datatime.getDate();
    if(day<10){day="0"+day};
    resultStr = year+'-'+month+'-'+day;
    return resultStr;
}

function endTimeToDate(obj){ // 日历结束时间
    var datatime = new Date(obj);
    var year = datatime.getFullYear();
    var month = datatime.getMonth()+6;
    if(month>12){
        year = year+1;
        month = month-12;
    }
    if(month<10){month="0"+month};
    var day = datatime.getDate();
    if(day<10){day="0"+day};
    resultStr = year+'-'+month+'-'+day;
    return resultStr;
}

